package com.rectcircle.wechat.ret.vo;

import com.rectcircle.wechat.util.Constants;

/**
 * 
 * 所有api返回消息的超类<br>
 * 封装了错误码和错误信息
 * 
 * @author RectCircle
 * @version 0.1<br>
 * 2016年7月31日-下午7:16:59<br>
 * Copyright (c) 2016 RectCircle-版权所有<br>
 *
 */
public class BasicReturn {
	private int errcode;
	private String errmsg;
	
	public BasicReturn() {
	}

	public int getErrcode() {
		return errcode;
	}

	/**
	 * 返回出错信息描述
	 * @return
	 */
	public String getErrDescription(){
		if(isError()){
			return "errcode: " + errcode + "," 
					+ " errmsg: " + errmsg + " (" 
					+ Constants.getRetMsgByCode(String.valueOf(errcode)) 
					+ ")";
		} else {
			return "errcode:0, errmsg: Successful! (请求成功)";
		}
	}

	public String getErrmsg() {
		return errmsg;
	}

	public boolean isError(){
		return errcode != 0;
	}

	public void setErrcode(int errcode) {
		this.errcode = errcode;
	}

	public void setErrmsg(String errmsg) {
		this.errmsg = errmsg;
	}
	
	@Override
	public String toString() {
		return "BasicReturn [errcode=" + errcode + ", errmsg=" + errmsg + "]";
	}
}
